/*
 * INSANE - Interactive Structural Analysis Environment
 *
 * Copyright (C) 2003-2006
 * Universidade Federal de Minas Gerais
 * Escola de Engenharia
 * Departamento de Engenharia de Estruturas
 *
 * Author's email :     insane@dees.ufmg.br
 * Author's Website :   http://www.dees.ufmg.br/insane
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */
 
package br.ufmg.dees.insane.draw;

import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
import java.util.ListIterator;
import java.util.Vector;

import br.ufmg.dees.insane.model.ModelState;

/**
 * @author Fonseca, Flavio & Pitangueira, Roque
 * @since	June 2004
 */
public abstract class GridLiberationDraw extends Draw {
	
	private static ModelState state;
	
//*****************************************************************************
	
	public void setModelState(ModelState a) {
		state = a;
	}
	
//*****************************************************************************
	
	public ModelState getModelState() {
		return state;
	}
	
//*****************************************************************************
//*****************************************************************************
	
    public static class X extends GridLiberationDraw {
         
        public X() {
            this(new Point(0, 0), 0);
        }
        
	//*****************************************************************************
		
        public X(Point loc) {
            this(loc, 0);
        }
        
	//*****************************************************************************
		
        public X(Point loc, double theta) {
            this(loc, theta, null);
        }
        
	//*****************************************************************************
		
        public X(Point loc, double theta, Object represents) {
            this.setLocation(loc);
            this.setAngle(theta);
            this.setRepresents(represents);
            this.setSize(new Dimension(32, 24));
        }
        
	//*****************************************************************************
		
		public void draw(Graphics2D g2) {
			
			Vector<Object> shapes = new Vector<Object>();
			Vector<Object> shapes2 = new Vector<Object>();
			
			int x = this.getLocation().x;
            int y = this.getLocation().y;
            double scale = this.getScale();
            double comp = 36 * scale;
			double larg = 15 * scale;
			double dist = 5 * scale;
			
			AffineTransform rot = new AffineTransform();
			rot.rotate(this.getAngle()*(-1), getLocation().x, getLocation().y);
			
			//"Erasing" a piece of the original element line
			g2.setColor(state.getBackground());
			g2.fill(rot.createTransformedShape(new Rectangle2D.Double(x, y-dist/2, larg, dist)));
			
			//Drawing the liberation representation
			shapes.clear();
			shapes2.clear();
			
			shapes.add(new Line2D.Double(x, y-comp/2, x+larg, y-comp/2));
			shapes.add(new Line2D.Double(x+larg, y-comp/2, x+larg, y+comp/2));
			shapes.add(new Line2D.Double(x+larg, y+comp/2, x, y+comp/2));
			shapes.add(new Line2D.Double(x, y+comp/2, x, y-comp/2));
			
			shapes2.add(new Rectangle2D.Double(x, y-comp/2, dist, comp));
			shapes2.add(new Rectangle2D.Double(x+larg-dist, y-comp/2, dist, comp));
			
			shapes.add(new Ellipse2D.Double(x+dist, y-(2.5*dist), dist, dist));
			shapes.add(new Ellipse2D.Double(x+dist, y-(0.5*dist), dist, dist));
			shapes.add(new Ellipse2D.Double(x+dist, y+(1.5*dist), dist, dist));
			
			g2.setColor(state.supportColor);
			ListIterator shps = shapes.listIterator();
			while(shps.hasNext()){
				g2.draw(rot.createTransformedShape((Shape)shps.next()));
			}
			shps = shapes2.listIterator();
			while(shps.hasNext()){
				g2.fill(rot.createTransformedShape((Shape)shps.next()));
			}
		}
		
	//*****************************************************************************
		
        public Vector<Object> getShapes() {
            return null;
        }
        
	//*****************************************************************************
		
        /**
         * Returns the draw bounds in device units.
         *
         * @return the draw bounds
         */
        public Rectangle getBounds() {
            
            int x = this.getLocation().x;
            int y = this.getLocation().y;
            int width = this.getSize().width;
            int height = this.getSize().height;
            double scale = this.getScale();
			
            int W = (int)(width * scale);
            int H = (int)(width * scale);
            int h = (int)(height/6 * scale);
            return new Rectangle((int)(x - W/2), y, W, H - h);
        }
        
    }
	
//*****************************************************************************
//*****************************************************************************
	
    public static class Y extends GridLiberationDraw {
         
        public Y() {
            this(new Point(0, 0), 0);
        }
        
	//*****************************************************************************
		
        public Y(Point loc) {
            this(loc, 0);
        }
        
	//*****************************************************************************
		
        public Y(Point loc, double theta) {
            this(loc, theta, null);
        }
        
	//*****************************************************************************
		
        public Y(Point loc, double theta, Object represents) {
            this.setLocation(loc);
            this.setAngle(theta);
            this.setRepresents(represents);
            this.setSize(new Dimension(32, 24));
        }
        
	//*****************************************************************************
		
		public void draw(Graphics2D g2) {
			
			Vector<Object> shapes = new Vector<Object>();
			
			int x = this.getLocation().x;
            int y = this.getLocation().y;
            double scale = this.getScale();
            double comp = 20 * scale;
			double dist = 5 * scale;
			
			AffineTransform rot = new AffineTransform();
			rot.rotate(this.getAngle()*(-1), getLocation().x, getLocation().y);
			
			//"Erasing" a piece of the original element line
			g2.setColor(state.getBackground());
			g2.fill(rot.createTransformedShape(new Rectangle2D.Double(x, y-dist/2, comp, dist)));
			
			//Drawing the liberation representation
			shapes.clear();
			
			shapes.add(new Line2D.Double(x, y-comp/2, x+comp, y-comp/2));
			shapes.add(new Line2D.Double(x+comp, y-comp/2, x+comp, y+comp/2));
			shapes.add(new Line2D.Double(x+comp, y+comp/2, x, y+comp/2));
			shapes.add(new Line2D.Double(x, y+comp/2, x, y-comp/2));
			
			shapes.add(new Line2D.Double(x+dist, y-comp/2+dist, x+comp-dist, y-comp/2+dist));
			shapes.add(new Line2D.Double(x+comp-dist, y-comp/2+dist, x+comp-dist, y+comp/2-dist));
			shapes.add(new Line2D.Double(x+comp-dist, y+comp/2-dist, x+dist, y+comp/2-dist));
			shapes.add(new Line2D.Double(x+dist, y+comp/2-dist, x+dist, y-comp/2+dist));
			
			shapes.add(new Ellipse2D.Double(x+comp/2-0.5*dist, y-comp/2, dist, dist));
			shapes.add(new Ellipse2D.Double(x+comp/2-0.5*dist, y+comp/2-dist, dist, dist));
			shapes.add(new Ellipse2D.Double(x, y-0.5*dist, dist, dist));
			shapes.add(new Ellipse2D.Double(x+comp-dist, y-0.5*dist, dist, dist));
			
			g2.setColor(state.supportColor);
			ListIterator shps = shapes.listIterator();
			while(shps.hasNext()){
				g2.draw(rot.createTransformedShape((Shape)shps.next()));
			}
			
		}
		
	//*****************************************************************************
		
        public Vector<Object> getShapes() {
            return null;
        }
        
	//*****************************************************************************
		
        /**
         * Returns the draw bounds in device units.
         *
         * @return the draw bounds
         */
        public Rectangle getBounds() {
            
            int x = this.getLocation().x;
            int y = this.getLocation().y;
            int width = this.getSize().width;
            int height = this.getSize().height;
            double scale = this.getScale();
			
            int W = (int)(width * scale);
            int H = (int)(width * scale);
            int h = (int)(height/6 * scale);
            return new Rectangle((int)(x - W/2), y, W, H - h);
        }
        
    }
	
//*****************************************************************************
//*****************************************************************************
	
	public static class Z extends GridLiberationDraw {
         
        public Z() {
            this(new Point(0, 0), 0);
        }
        
	//*****************************************************************************
		
        public Z(Point loc) {
            this(loc, 0);
        }
        
	//*****************************************************************************
		
        public Z(Point loc, double theta) {
            this(loc, theta, null);
        }
        
	//*****************************************************************************
		
        public Z(Point loc, double theta, Object represents) {
            this.setLocation(loc);
            this.setAngle(theta);
            this.setRepresents(represents);
            this.setSize(new Dimension(32, 24));
        }
        
	//*****************************************************************************
		
		public void draw(Graphics2D g2) {
			
			Vector<Object> shapes = new Vector<Object>();
			Vector<Object> shapes2 = new Vector<Object>();
			
			int x = this.getLocation().x;
            int y = this.getLocation().y;
            double scale = this.getScale();
			double comp = 36 * scale;
			double larg = 15 * scale;
			double dist = 5 * scale;
			
			AffineTransform rot = new AffineTransform();
			rot.rotate(this.getAngle()*(-1), getLocation().x, getLocation().y);
			
			//"Erasing" a piece of the original element line
			g2.setColor(state.getBackground());
			g2.fill(rot.createTransformedShape(new Ellipse2D.Double(x, y-(0.5*dist), comp, dist)));
			
			//Drawing the liberation representation
			shapes.clear();
			shapes2.clear();
			
			shapes.add(new Line2D.Double(x, y-larg/2, x+comp, y-larg/2));
			shapes.add(new Line2D.Double(x+comp, y-larg/2, x+comp, y+larg/2));
			shapes.add(new Line2D.Double(x+comp, y+larg/2, x, y+larg/2));
			shapes.add(new Line2D.Double(x, y+larg/2, x, y-larg/2));
			
			shapes2.add(new Rectangle2D.Double(x, y-larg/2, comp, dist));
			shapes2.add(new Rectangle2D.Double(x, y+larg/2-dist, comp, dist));
			
			/*
			shapes.add(new Line2D.Double(x, y-larg/2+dist, x+comp, y-larg/2+dist));
			shapes.add(new Line2D.Double(x, y-larg/2, x+dist, y-larg/2+dist));
			shapes.add(new Line2D.Double(x+dist, y-larg/2, x+2*dist, y-larg/2+dist));
			shapes.add(new Line2D.Double(x+2*dist, y-larg/2, x+3*dist, y-larg/2+dist));
			shapes.add(new Line2D.Double(x+3*dist, y-larg/2, x+4*dist, y-larg/2+dist));
			shapes.add(new Line2D.Double(x+4*dist, y-larg/2, x+5*dist, y-larg/2+dist));
			shapes.add(new Line2D.Double(x+5*dist, y-larg/2, x+6*dist, y-larg/2+dist));
			shapes.add(new Line2D.Double(x+6*dist, y-larg/2, x+7*dist, y-larg/2+dist));
			
			shapes.add(new Line2D.Double(x, y+larg/2-dist, x+comp, y+larg/2-dist));
			shapes.add(new Line2D.Double(x, y+larg/2-dist, x+dist, y+larg/2));
			shapes.add(new Line2D.Double(x+dist, y+larg/2-dist, x+2*dist, y+larg/2));
			shapes.add(new Line2D.Double(x+2*dist, y+larg/2-dist, x+3*dist, y+larg/2));
			shapes.add(new Line2D.Double(x+3*dist, y+larg/2-dist, x+4*dist, y+larg/2));
			shapes.add(new Line2D.Double(x+4*dist, y+larg/2-dist, x+5*dist, y+larg/2));
			shapes.add(new Line2D.Double(x+5*dist, y+larg/2-dist, x+6*dist, y+larg/2));
			shapes.add(new Line2D.Double(x+6*dist, y+larg/2-dist, x+7*dist, y+larg/2));
			*/
			
			shapes.add(new Ellipse2D.Double(x+comp/2-2.5*dist, y-(0.5*dist), dist, dist));
			shapes.add(new Ellipse2D.Double(x+comp/2-0.5*dist, y-(0.5*dist), dist, dist));
			shapes.add(new Ellipse2D.Double(x+comp/2+1.5*dist, y-(0.5*dist), dist, dist));
			
			g2.setColor(state.supportColor);
			ListIterator shps = shapes.listIterator();
			while(shps.hasNext()){
				g2.draw(rot.createTransformedShape((Shape)shps.next()));
			}
			shps = shapes2.listIterator();
			while(shps.hasNext()){
				g2.fill(rot.createTransformedShape((Shape)shps.next()));
			}
			
		}
		
	//*****************************************************************************
		
        public Vector<Object> getShapes() {
            return null;
        }
        
	//*****************************************************************************
		
        /**
         * Returns the draw bounds in device units.
         *
         * @return the draw bounds
         */
        public Rectangle getBounds() {
            
            int x = this.getLocation().x;
            int y = this.getLocation().y;
            int width = this.getSize().width;
            int height = this.getSize().height;
            double scale = this.getScale();
			
            int W = (int)(width * scale);
            int H = (int)(width * scale);
            int h = (int)(height/6 * scale);
            return new Rectangle((int)(x - W/2), y, W, H - h);
        }
        
    }
	
//*****************************************************************************
//*****************************************************************************
	
    public static class XY extends GridLiberationDraw {
         
        public XY() {
            this(new Point(0, 0), 0);
        }
        
	//*****************************************************************************
		
        public XY(Point loc) {
            this(loc, 0);
        }
        
	//*****************************************************************************
		
        public XY(Point loc, double theta) {
            this(loc, theta, null);
        }
        
	//*****************************************************************************
		
        public XY(Point loc, double theta, Object represents) {
            this.setLocation(loc);
            this.setAngle(theta);
            this.setRepresents(represents);
            this.setSize(new Dimension(32, 24));
        }
        
	//*****************************************************************************
		
		public void draw(Graphics2D g2) {
			
			Vector<Object> shapes = new Vector<Object>();
			Vector<Object> shapes2 = new Vector<Object>();
			
			int x = this.getLocation().x;
            int y = this.getLocation().y;
            double scale = this.getScale();
            double comp = 20 * scale;
			double dist = 5 * scale;
			double comp2 = 36 * scale;
			double larg = 15 * scale;
			
			AffineTransform rot = new AffineTransform();
			rot.rotate(this.getAngle()*(-1), getLocation().x, getLocation().y);
			
			//"Erasing" a piece of the original element line
			g2.setColor(state.getBackground());
			g2.fill(rot.createTransformedShape(new Rectangle2D.Double(x, y-dist/2, comp, dist)));
			g2.fill(rot.createTransformedShape(new Rectangle2D.Double(x+comp, y-dist/2, larg, dist)));
			
			//Drawing the liberation representation
			shapes.clear();
			shapes2.clear();
			
			//Dy
			shapes.add(new Line2D.Double(x, y-comp/2, x+comp, y-comp/2));
			shapes.add(new Line2D.Double(x+comp, y-comp/2, x+comp, y+comp/2));
			shapes.add(new Line2D.Double(x+comp, y+comp/2, x, y+comp/2));
			shapes.add(new Line2D.Double(x, y+comp/2, x, y-comp/2));
			shapes.add(new Line2D.Double(x+dist, y-comp/2+dist, x+comp-dist, y-comp/2+dist));
			shapes.add(new Line2D.Double(x+comp-dist, y-comp/2+dist, x+comp-dist, y+comp/2-dist));
			shapes.add(new Line2D.Double(x+comp-dist, y+comp/2-dist, x+dist, y+comp/2-dist));
			shapes.add(new Line2D.Double(x+dist, y+comp/2-dist, x+dist, y-comp/2+dist));
			shapes.add(new Ellipse2D.Double(x+comp/2-0.5*dist, y-comp/2, dist, dist));
			shapes.add(new Ellipse2D.Double(x+comp/2-0.5*dist, y+comp/2-dist, dist, dist));
			shapes.add(new Ellipse2D.Double(x, y-0.5*dist, dist, dist));
			shapes.add(new Ellipse2D.Double(x+comp-dist, y-0.5*dist, dist, dist));
			
			//Rx
			x = (int)(x+comp);
			shapes.add(new Line2D.Double(x, y-comp2/2, x+larg, y-comp2/2));
			shapes.add(new Line2D.Double(x+larg, y-comp2/2, x+larg, y+comp2/2));
			shapes.add(new Line2D.Double(x+larg, y+comp2/2, x, y+comp2/2));
			shapes.add(new Line2D.Double(x, y+comp2/2, x, y-comp2/2));
			shapes2.add(new Rectangle2D.Double(x, y-comp2/2, dist, comp2));
			shapes2.add(new Rectangle2D.Double(x+larg-dist, y-comp2/2, dist, comp2));
			shapes.add(new Ellipse2D.Double(x+dist, y-(2.5*dist), dist, dist));
			shapes.add(new Ellipse2D.Double(x+dist, y-(0.5*dist), dist, dist));
			shapes.add(new Ellipse2D.Double(x+dist, y+(1.5*dist), dist, dist));
			
			g2.setColor(state.supportColor);
			ListIterator shps = shapes.listIterator();
			while(shps.hasNext()){
				g2.draw(rot.createTransformedShape((Shape)shps.next()));
			}
			shps = shapes2.listIterator();
			while(shps.hasNext()){
				g2.fill(rot.createTransformedShape((Shape)shps.next()));
			}
			
		}
		
	//*****************************************************************************
		
        public Vector<Object> getShapes() {
            return null;
        }
        
	//*****************************************************************************
		
        /**
         * Returns the draw bounds in device units.
         *
         * @return the draw bounds
         */
        public Rectangle getBounds() {
            
            int x = this.getLocation().x;
            int y = this.getLocation().y;
            int width = this.getSize().width;
            int height = this.getSize().height;
            double scale = this.getScale();
			
            int W = (int)(width * scale);
            int H = (int)(width * scale);
            int h = (int)(height/6 * scale);
            return new Rectangle((int)(x - W/2), y, W, H - h);
        }
        
    }

//*****************************************************************************
//*****************************************************************************
	
    public static class XZ extends GridLiberationDraw {
         
        public XZ() {
            this(new Point(0, 0), 0);
        }
        
	//*****************************************************************************
		
        public XZ(Point loc) {
            this(loc, 0);
        }
        
	//*****************************************************************************
		
        public XZ(Point loc, double theta) {
            this(loc, theta, null);
        }
        
	//*****************************************************************************
		
        public XZ(Point loc, double theta, Object represents) {
            this.setLocation(loc);
            this.setAngle(theta);
            this.setRepresents(represents);
            this.setSize(new Dimension(32, 24));
        }
        
	//*****************************************************************************
		
		public void draw(Graphics2D g2) {
			Vector<Object> shapes = new Vector<Object>();
			Vector<Object> shapes2 = new Vector<Object>();
			
			int x = this.getLocation().x;
            int y = this.getLocation().y;
            double scale = this.getScale();
            double comp = 36 * scale;
			double larg = 15 * scale;
			double dist = 5 * scale;
			
			AffineTransform rot = new AffineTransform();
			rot.rotate(this.getAngle()*(-1), getLocation().x, getLocation().y);
			
			//"Erasing" a piece of the original element line
			g2.setColor(state.getBackground());
			g2.fill(rot.createTransformedShape(new Rectangle2D.Double(x, y-dist/2, larg, dist)));
			g2.fill(rot.createTransformedShape(new Ellipse2D.Double(x+larg, y-(0.5*dist), comp, dist)));
			
			//Drawing the liberation representation
			shapes.clear();
			shapes2.clear();
			
			//Rx
			shapes.add(new Line2D.Double(x, y-comp/2, x+larg, y-comp/2));
			shapes.add(new Line2D.Double(x+larg, y-comp/2, x+larg, y+comp/2));
			shapes.add(new Line2D.Double(x+larg, y+comp/2, x, y+comp/2));
			shapes.add(new Line2D.Double(x, y+comp/2, x, y-comp/2));
			shapes2.add(new Rectangle2D.Double(x, y-comp/2, dist, comp));
			shapes2.add(new Rectangle2D.Double(x+larg-dist, y-comp/2, dist, comp));
			shapes.add(new Ellipse2D.Double(x+dist, y-(2.5*dist), dist, dist));
			shapes.add(new Ellipse2D.Double(x+dist, y-(0.5*dist), dist, dist));
			shapes.add(new Ellipse2D.Double(x+dist, y+(1.5*dist), dist, dist));
			
			//Rz
			x = (int)(x+larg);
			shapes.add(new Line2D.Double(x, y-larg/2, x+comp, y-larg/2));
			shapes.add(new Line2D.Double(x+comp, y-larg/2, x+comp, y+larg/2));
			shapes.add(new Line2D.Double(x+comp, y+larg/2, x, y+larg/2));
			shapes.add(new Line2D.Double(x, y+larg/2, x, y-larg/2));
			shapes2.add(new Rectangle2D.Double(x, y-larg/2, comp, dist));
			shapes2.add(new Rectangle2D.Double(x, y+larg/2-dist, comp, dist));
			shapes.add(new Ellipse2D.Double(x+comp/2-2.5*dist, y-(0.5*dist), dist, dist));
			shapes.add(new Ellipse2D.Double(x+comp/2-0.5*dist, y-(0.5*dist), dist, dist));
			shapes.add(new Ellipse2D.Double(x+comp/2+1.5*dist, y-(0.5*dist), dist, dist));
			
			g2.setColor(state.supportColor);
			ListIterator shps = shapes.listIterator();
			while(shps.hasNext()){
				g2.draw(rot.createTransformedShape((Shape)shps.next()));
			}
			shps = shapes2.listIterator();
			while(shps.hasNext()){
				g2.fill(rot.createTransformedShape((Shape)shps.next()));
			}
		}
		
	//*****************************************************************************
		
        public Vector<Object> getShapes() {
            return null;
        }
        
	//*****************************************************************************
		
        /**
         * Returns the draw bounds in device units.
         *
         * @return the draw bounds
         */
        public Rectangle getBounds() {
            
            int x = this.getLocation().x;
            int y = this.getLocation().y;
            int width = this.getSize().width;
            int height = this.getSize().height;
            double scale = this.getScale();
			
            int W = (int)(width * scale);
            int H = (int)(width * scale);
            int h = (int)(height/6 * scale);
            return new Rectangle((int)(x - W/2), y, W, H - h);
        }
        
    }

//*****************************************************************************
//*****************************************************************************
	
    public static class YZ extends GridLiberationDraw {
         
        public YZ() {
            this(new Point(0, 0), 0);
        }
        
	//*****************************************************************************
		
        public YZ(Point loc) {
            this(loc, 0);
        }
        
	//*****************************************************************************
		
        public YZ(Point loc, double theta) {
            this(loc, theta, null);
        }
        
	//*****************************************************************************
		
        public YZ(Point loc, double theta, Object represents) {
            this.setLocation(loc);
            this.setAngle(theta);
            this.setRepresents(represents);
            this.setSize(new Dimension(32, 24));
        }
        
	//*****************************************************************************
		
		public void draw(Graphics2D g2) {
			
			Vector<Object> shapes = new Vector<Object>();
			Vector<Object> shapes2 = new Vector<Object>();
			
			int x = this.getLocation().x;
            int y = this.getLocation().y;
            double scale = this.getScale();
            double comp = 20 * scale;
			double dist = 5 * scale;
			double comp2 = 36 * scale;
			double larg = 15 * scale;
			
			AffineTransform rot = new AffineTransform();
			rot.rotate(this.getAngle()*(-1), getLocation().x, getLocation().y);
			
			//"Erasing" a piece of the original element line
			g2.setColor(state.getBackground());
			g2.fill(rot.createTransformedShape(new Rectangle2D.Double(x, y-dist/2, comp, dist)));
			g2.fill(rot.createTransformedShape(new Ellipse2D.Double(x+comp, y-(0.5*dist), comp2, dist)));
			
			//Drawing the liberation representation
			shapes.clear();
			shapes2.clear();
			
			//Dy
			shapes.add(new Line2D.Double(x, y-comp/2, x+comp, y-comp/2));
			shapes.add(new Line2D.Double(x+comp, y-comp/2, x+comp, y+comp/2));
			shapes.add(new Line2D.Double(x+comp, y+comp/2, x, y+comp/2));
			shapes.add(new Line2D.Double(x, y+comp/2, x, y-comp/2));
			shapes.add(new Line2D.Double(x+dist, y-comp/2+dist, x+comp-dist, y-comp/2+dist));
			shapes.add(new Line2D.Double(x+comp-dist, y-comp/2+dist, x+comp-dist, y+comp/2-dist));
			shapes.add(new Line2D.Double(x+comp-dist, y+comp/2-dist, x+dist, y+comp/2-dist));
			shapes.add(new Line2D.Double(x+dist, y+comp/2-dist, x+dist, y-comp/2+dist));
			shapes.add(new Ellipse2D.Double(x+comp/2-0.5*dist, y-comp/2, dist, dist));
			shapes.add(new Ellipse2D.Double(x+comp/2-0.5*dist, y+comp/2-dist, dist, dist));
			shapes.add(new Ellipse2D.Double(x, y-0.5*dist, dist, dist));
			shapes.add(new Ellipse2D.Double(x+comp-dist, y-0.5*dist, dist, dist));
			
			//Rz
			x = (int)(x+comp);
			shapes.add(new Line2D.Double(x, y-larg/2, x+comp2, y-larg/2));
			shapes.add(new Line2D.Double(x+comp2, y-larg/2, x+comp2, y+larg/2));
			shapes.add(new Line2D.Double(x+comp2, y+larg/2, x, y+larg/2));
			shapes.add(new Line2D.Double(x, y+larg/2, x, y-larg/2));
			shapes2.add(new Rectangle2D.Double(x, y-larg/2, comp2, dist));
			shapes2.add(new Rectangle2D.Double(x, y+larg/2-dist, comp2, dist));
			shapes.add(new Ellipse2D.Double(x+comp2/2-2.5*dist, y-(0.5*dist), dist, dist));
			shapes.add(new Ellipse2D.Double(x+comp2/2-0.5*dist, y-(0.5*dist), dist, dist));
			shapes.add(new Ellipse2D.Double(x+comp2/2+1.5*dist, y-(0.5*dist), dist, dist));
			
			g2.setColor(state.supportColor);
			ListIterator shps = shapes.listIterator();
			while(shps.hasNext()){
				g2.draw(rot.createTransformedShape((Shape)shps.next()));
			}
			shps = shapes2.listIterator();
			while(shps.hasNext()){
				g2.fill(rot.createTransformedShape((Shape)shps.next()));
			}
			
		}
		
	//*****************************************************************************
		
        public Vector<Object> getShapes() {
            return null;
        }
        
	//*****************************************************************************
		
        /**
         * Returns the draw bounds in device units.
         *
         * @return the draw bounds
         */
        public Rectangle getBounds() {
            
            int x = this.getLocation().x;
            int y = this.getLocation().y;
            int width = this.getSize().width;
            int height = this.getSize().height;
            double scale = this.getScale();
			
            int W = (int)(width * scale);
            int H = (int)(width * scale);
            int h = (int)(height/6 * scale);
            return new Rectangle((int)(x - W/2), y, W, H - h);
        }
        
    }

//*****************************************************************************
//*****************************************************************************
	
    public static class XYZ extends GridLiberationDraw {
         
        public XYZ() {
            this(new Point(0, 0), 0);
        }
        
	//*****************************************************************************
		
        public XYZ(Point loc) {
            this(loc, 0);
        }
        
	//*****************************************************************************
		
        public XYZ(Point loc, double theta) {
            this(loc, theta, null);
        }
        
	//*****************************************************************************
		
        public XYZ(Point loc, double theta, Object represents) {
            this.setLocation(loc);
            this.setAngle(theta);
            this.setRepresents(represents);
            this.setSize(new Dimension(32, 24));
        }
        
	//*****************************************************************************
		
		public void draw(Graphics2D g2) {
			
			Vector<Object> shapes = new Vector<Object>();
			Vector<Object> shapes2 = new Vector<Object>();
			
			int x = this.getLocation().x;
            int y = this.getLocation().y;
            double scale = this.getScale();
            double comp = 20 * scale;
			double dist = 5 * scale;
			double comp2 = 36 * scale;
			double larg = 15 * scale;
			
			AffineTransform rot = new AffineTransform();
			rot.rotate(this.getAngle()*(-1), getLocation().x, getLocation().y);
			
			//"Erasing" a piece of the original element line
			g2.setColor(state.getBackground());
			g2.fill(rot.createTransformedShape(new Rectangle2D.Double(x, y-dist/2, comp, dist)));
			g2.fill(rot.createTransformedShape(new Rectangle2D.Double(x+comp, y-dist/2, larg, dist)));
			g2.fill(rot.createTransformedShape(new Ellipse2D.Double(x+comp+larg, y-(0.5*dist), comp2, dist)));
			
			//Drawing the liberation representation
			shapes.clear();
			shapes2.clear();
			
			//Dy
			shapes.add(new Line2D.Double(x, y-comp/2, x+comp, y-comp/2));
			shapes.add(new Line2D.Double(x+comp, y-comp/2, x+comp, y+comp/2));
			shapes.add(new Line2D.Double(x+comp, y+comp/2, x, y+comp/2));
			shapes.add(new Line2D.Double(x, y+comp/2, x, y-comp/2));
			shapes.add(new Line2D.Double(x+dist, y-comp/2+dist, x+comp-dist, y-comp/2+dist));
			shapes.add(new Line2D.Double(x+comp-dist, y-comp/2+dist, x+comp-dist, y+comp/2-dist));
			shapes.add(new Line2D.Double(x+comp-dist, y+comp/2-dist, x+dist, y+comp/2-dist));
			shapes.add(new Line2D.Double(x+dist, y+comp/2-dist, x+dist, y-comp/2+dist));
			shapes.add(new Ellipse2D.Double(x+comp/2-0.5*dist, y-comp/2, dist, dist));
			shapes.add(new Ellipse2D.Double(x+comp/2-0.5*dist, y+comp/2-dist, dist, dist));
			shapes.add(new Ellipse2D.Double(x, y-0.5*dist, dist, dist));
			shapes.add(new Ellipse2D.Double(x+comp-dist, y-0.5*dist, dist, dist));
			
			//Rx
			x = (int)(x+comp);
			shapes.add(new Line2D.Double(x, y-comp2/2, x+larg, y-comp2/2));
			shapes.add(new Line2D.Double(x+larg, y-comp2/2, x+larg, y+comp2/2));
			shapes.add(new Line2D.Double(x+larg, y+comp2/2, x, y+comp2/2));
			shapes.add(new Line2D.Double(x, y+comp2/2, x, y-comp2/2));
			shapes2.add(new Rectangle2D.Double(x, y-comp2/2, dist, comp2));
			shapes2.add(new Rectangle2D.Double(x+larg-dist, y-comp2/2, dist, comp2));
			shapes.add(new Ellipse2D.Double(x+dist, y-(2.5*dist), dist, dist));
			shapes.add(new Ellipse2D.Double(x+dist, y-(0.5*dist), dist, dist));
			shapes.add(new Ellipse2D.Double(x+dist, y+(1.5*dist), dist, dist));
			
			//Rz
			x = (int)(x+larg);
			shapes.add(new Line2D.Double(x, y-larg/2, x+comp2, y-larg/2));
			shapes.add(new Line2D.Double(x+comp2, y-larg/2, x+comp2, y+larg/2));
			shapes.add(new Line2D.Double(x+comp2, y+larg/2, x, y+larg/2));
			shapes.add(new Line2D.Double(x, y+larg/2, x, y-larg/2));
			shapes2.add(new Rectangle2D.Double(x, y-larg/2, comp2, dist));
			shapes2.add(new Rectangle2D.Double(x, y+larg/2-dist, comp2, dist));
			shapes.add(new Ellipse2D.Double(x+comp2/2-2.5*dist, y-(0.5*dist), dist, dist));
			shapes.add(new Ellipse2D.Double(x+comp2/2-0.5*dist, y-(0.5*dist), dist, dist));
			shapes.add(new Ellipse2D.Double(x+comp2/2+1.5*dist, y-(0.5*dist), dist, dist));
			
			g2.setColor(state.supportColor);
			ListIterator shps = shapes.listIterator();
			while(shps.hasNext()){
				g2.draw(rot.createTransformedShape((Shape)shps.next()));
			}
			shps = shapes2.listIterator();
			while(shps.hasNext()){
				g2.fill(rot.createTransformedShape((Shape)shps.next()));
			}
			
		}
		
	//*****************************************************************************
		
        public Vector<Object> getShapes() {
            return null;
        }
        
	//*****************************************************************************
		
        /**
         * Returns the draw bounds in device units.
         *
         * @return the draw bounds
         */
        public Rectangle getBounds() {
            
            int x = this.getLocation().x;
            int y = this.getLocation().y;
            int width = this.getSize().width;
            int height = this.getSize().height;
            double scale = this.getScale();
			
            int W = (int)(width * scale);
            int H = (int)(width * scale);
            int h = (int)(height/6 * scale);
            return new Rectangle((int)(x - W/2), y, W, H - h);
        }
        
    }

//*****************************************************************************
//*****************************************************************************
}
